﻿IF OBJECT_ID('cms_user_UserBase') IS NOT NULL
BEGIN
    DROP TABLE cms_user_UserBase
    PRINT '<<< DROPPED TABLE cms_user_UserBase >>>'
END
GO
CREATE TABLE cms_user_UserBase(
    UserBaseId     int              IDENTITY(1,1),
    LogName        nvarchar(200)    NULL,
    LogPWD         varchar(200)     NULL,
    Name           nvarchar(200)    NULL,
    Sex            bit              DEFAULT 0 NOT NULL,
    LastLogTime    datetime         DEFAULT getdate() NOT NULL,
    AddTime        datetime         DEFAULT getdate() NOT NULL,
    PubCount       int              NULL,
    CONSTRAINT PK__cms_user_UserBase PRIMARY KEY NONCLUSTERED (UserBaseId)
)
GO
IF OBJECT_ID('cms_user_UserBase') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_user_UserBase >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_user_UserBase >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'UserBaseId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'UserBaseId'
END
exec sys.sp_addextendedproperty 'MS_Description', 'UserBaseId', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'UserBaseId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LogName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LogName'
END
exec sys.sp_addextendedproperty 'MS_Description', 'LogName', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LogName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LogPWD'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LogPWD'
END
exec sys.sp_addextendedproperty 'MS_Description', 'LogPWD', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LogPWD'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Name', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'Sex'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'Sex'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Sex', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'Sex'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LastLogTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LastLogTime'
END
exec sys.sp_addextendedproperty 'MS_Description', 'LastLogTime', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'LastLogTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', 'AddTime', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'PubCount'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'PubCount'
END
exec sys.sp_addextendedproperty 'MS_Description', 'PubCount', 'schema', 'dbo', 'table', 'cms_user_UserBase', 'column', 'PubCount'
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_UserBase_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_UserBase_Save
GO 
CREATE PROCEDURE cms_UserBase_Save
@UserBaseId    	int OUTPUT,
@LogName    	nvarchar(200),
@LogPWD    	varchar(200),
@Name    	nvarchar(200),
@Sex    	bit,
@LastLogTime    	datetime,
@AddTime    	datetime,
@PubCount    	int
AS
IF (@UserBaseId>0) 
BEGIN
	UPDATE cms_user_UserBase
	SET 
		[LogName] = @LogName,
		[LogPWD] = @LogPWD,
		[Name] = @Name,
		[Sex] = @Sex,
		[LastLogTime] = @LastLogTime,
		[AddTime] = @AddTime,
		[PubCount] = @PubCount
	WHERE [UserBaseId]=@UserBaseId
END
ELSE
BEGIN
	INSERT INTO cms_user_UserBase([LogName],[LogPWD],[Name],[Sex],[LastLogTime],[AddTime],[PubCount])
	VALUES(@LogName,@LogPWD,@Name,@Sex,@LastLogTime,@AddTime,@PubCount)
	SET @UserBaseId = @@IDENTITY
END
GO
IF OBJECT_ID('cms_rec_Recom') IS NOT NULL
BEGIN
    DROP TABLE cms_rec_Recom
    PRINT '<<< DROPPED TABLE cms_rec_Recom >>>'
END
GO
IF OBJECT_ID('cms_rec_RecomContent') IS NOT NULL
BEGIN
    DROP TABLE cms_rec_RecomContent
    PRINT '<<< DROPPED TABLE cms_rec_RecomContent >>>'
END
GO
IF OBJECT_ID('cms_rec_RecomTemplate') IS NOT NULL
BEGIN
    DROP TABLE cms_rec_RecomTemplate
    PRINT '<<< DROPPED TABLE cms_rec_RecomTemplate >>>'
END
GO
CREATE TABLE cms_rec_Recom(
    RecommendId    int              IDENTITY(1,1),
    Name           nvarchar(200)    NULL,
    Detail         ntext            NOT NULL,
    CONSTRAINT PK__cms_rec_Recommend PRIMARY KEY NONCLUSTERED (RecommendId)
)
GO
IF OBJECT_ID('cms_rec_Recom') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_rec_Recom >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_rec_Recom >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'RecommendId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'RecommendId'
END
exec sys.sp_addextendedproperty 'MS_Description', '评论id', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'RecommendId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', '标题', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'Detail'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'Detail'
END
exec sys.sp_addextendedproperty 'MS_Description', '评论内容', 'schema', 'dbo', 'table', 'cms_rec_Recom', 'column', 'Detail'
GO
CREATE TABLE cms_rec_RecomContent(
    RecomId        int              DEFAULT 0 NOT NULL,
    ContentId      int              DEFAULT 0 NULL,
    IsAnonymity    bit              DEFAULT 0 NOT NULL,
    AddUserId      int              DEFAULT 0 NOT NULL,
    UserName       nvarchar(200)    NULL,
    AddTime        datetime         DEFAULT getdate() NOT NULL,
    IsAudit        bit              DEFAULT 0 NOT NULL,
    IP             nvarchar(20)     NULL,
    CONSTRAINT PK__cms_rec_Recommend_1 PRIMARY KEY NONCLUSTERED (RecomId)
)
GO
IF OBJECT_ID('cms_rec_RecomContent') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_rec_RecomContent >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_rec_RecomContent >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'RecomId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'RecomId'
END
exec sys.sp_addextendedproperty 'MS_Description', '评论信息id', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'RecomId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'ContentId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'ContentId'
END
exec sys.sp_addextendedproperty 'MS_Description', '内容id', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'ContentId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IsAnonymity'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IsAnonymity'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否匿名', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IsAnonymity'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '用户id', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'UserName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'UserName'
END
exec sys.sp_addextendedproperty 'MS_Description', '用户称谓', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'UserName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '评论时间', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IsAudit'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IsAudit'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否审核通过', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IsAudit'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IP'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IP'
END
exec sys.sp_addextendedproperty 'MS_Description', '评论者IP', 'schema', 'dbo', 'table', 'cms_rec_RecomContent', 'column', 'IP'
GO
CREATE TABLE cms_rec_RecomTemplate(
    NodeId          int             DEFAULT 0 NOT NULL,
    TemplateRoot    varchar(300)    NOT NULL,
    AddTime         datetime        DEFAULT getdate() NOT NULL,
    AddUserId       int             DEFAULT 0 NOT NULL,
    UpdateTime      datetime        DEFAULT getdate() NOT NULL,
    CONSTRAINT PK__cms_rec_Recommend_1_1 PRIMARY KEY NONCLUSTERED (NodeId)
)
GO
IF OBJECT_ID('cms_rec_RecomTemplate') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_rec_RecomTemplate >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_rec_RecomTemplate >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'NodeId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'NodeId'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点ID', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'NodeId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'TemplateRoot'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'TemplateRoot'
END
exec sys.sp_addextendedproperty 'MS_Description', '模板文件地址', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'TemplateRoot'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'UpdateTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'UpdateTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改时间', 'schema', 'dbo', 'table', 'cms_rec_RecomTemplate', 'column', 'UpdateTime'
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_Recom_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_Recom_Save
GO 
CREATE PROCEDURE cms_Recom_Save
@RecommendId    	int OUTPUT,
@Name    	nvarchar(200),
@Detail    	ntext
AS
IF (@RecommendId>0) 
BEGIN
	UPDATE cms_rec_Recom
	SET 
		[Name] = @Name,
		[Detail] = @Detail
	WHERE [RecommendId]=@RecommendId
END
ELSE
BEGIN
	INSERT INTO cms_rec_Recom([Name],[Detail])
	VALUES(@Name,@Detail)
	SET @RecommendId = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_RecomContent_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_RecomContent_Save
GO 
CREATE PROCEDURE cms_RecomContent_Save
@RecomId    	int OUTPUT,
@ContentId    	int,
@IsAnonymity    	bit,
@AddUserId    	int,
@UserName    	nvarchar(200),
@AddTime    	datetime,
@IsAudit    	bit,
@IP    	nvarchar(20)
AS
declare @id int
select @id=count(0) from cms_rec_RecomContent where RecomId=@RecomId
IF (@id>0)
BEGIN
	UPDATE cms_rec_RecomContent
	SET 
		[ContentId] = @ContentId,
		[IsAnonymity] = @IsAnonymity,
		[AddUserId] = @AddUserId,
		[UserName] = @UserName,
		[AddTime] = @AddTime,
		[IsAudit] = @IsAudit,
		[IP] = @IP
	WHERE [RecomId]=@RecomId
END
ELSE
BEGIN
	INSERT INTO cms_rec_RecomContent([RecomId],[ContentId],[IsAnonymity],[AddUserId],[UserName],[AddTime],[IsAudit],[IP])
	VALUES(@RecomId,@ContentId,@IsAnonymity,@AddUserId,@UserName,@AddTime,@IsAudit,@IP)
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_RecomTemplate_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_RecomTemplate_Save
GO 
CREATE PROCEDURE cms_RecomTemplate_Save
@NodeId    	int OUTPUT,
@TemplateRoot    	varchar(300),
@AddTime    	datetime,
@AddUserId    	int,
@UpdateTime    	datetime
AS
declare @id int
select @id=count(0) from cms_rec_RecomTemplate where nodeid=@NodeId
IF (@id>0)
BEGIN
	UPDATE cms_rec_RecomTemplate
	SET 
		[TemplateRoot] = @TemplateRoot,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId,
		[UpdateTime] = @UpdateTime
	WHERE [NodeId]=@NodeId
END
ELSE
BEGIN
	INSERT INTO cms_rec_RecomTemplate([NodeId],[TemplateRoot],[AddTime],[AddUserId],[UpdateTime])
	VALUES(@NodeId,@TemplateRoot,@AddTime,@AddUserId,@UpdateTime)
END
GO
IF OBJECT_ID('cms_content_ContentUpFile') IS NOT NULL
BEGIN
    DROP TABLE cms_content_ContentUpFile
    PRINT '<<< DROPPED TABLE cms_content_ContentUpFile >>>'
END
GO
CREATE TABLE cms_content_ContentUpFile(
    ContentUpFileId    int               IDENTITY(1,1),
    NodeID             int               DEFAULT 0 NULL,
    ContentId          int               DEFAULT 0 NULL,
    FileRoot           nvarchar(500)     NOT NULL,
    Category           varchar(100)      NOT NULL,
    AttributeID        int               DEFAULT 0 NULL,
    AddTime            datetime          DEFAULT getdate() NOT NULL,
    AddUserId          int               DEFAULT 0 NOT NULL,
    FileSize           decimal(10, 2)    DEFAULT 0 NULL,
    CONSTRAINT PK__cms_content_ContentUpFile PRIMARY KEY NONCLUSTERED (ContentUpFileId)
)
GO
IF OBJECT_ID('cms_content_ContentUpFile') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_content_ContentUpFile >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_content_ContentUpFile >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'NodeID'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'NodeID'
END
exec sys.sp_addextendedproperty 'MS_Description', '结点ID', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'NodeID'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'ContentId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'ContentId'
END
exec sys.sp_addextendedproperty 'MS_Description', '信息基表id', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'ContentId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'FileRoot'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'FileRoot'
END
exec sys.sp_addextendedproperty 'MS_Description', '文件地址', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'FileRoot'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AttributeID'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AttributeID'
END
exec sys.sp_addextendedproperty 'MS_Description', '属性ID', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AttributeID'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'FileSize'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'FileSize'
END
exec sys.sp_addextendedproperty 'MS_Description', '附件大小(K单位)', 'schema', 'dbo', 'table', 'cms_content_ContentUpFile', 'column', 'FileSize'
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_ContentUpFile_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_ContentUpFile_Save
GO 
CREATE PROCEDURE cms_ContentUpFile_Save
@ContentUpFileId    	int OUTPUT,
@NodeID    	int,
@ContentId    	int,
@FileRoot    	nvarchar(500),
@Category    	varchar(100),
@AttributeID    	int,
@AddTime    	datetime,
@AddUserId    	int,
@FileSize    	decimal(10,2)
AS
IF (@ContentUpFileId>0) 
BEGIN
	UPDATE cms_content_ContentUpFile
	SET 
		[NodeID] = @NodeID,
		[ContentId] = @ContentId,
		[FileRoot] = @FileRoot,
		[Category] = @Category,
		[AttributeID] = @AttributeID,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId,
		[FileSize] = @FileSize
	WHERE [ContentUpFileId]=@ContentUpFileId
END
ELSE
BEGIN
	INSERT INTO cms_content_ContentUpFile([NodeID],[ContentId],[FileRoot],[Category],[AttributeID],[AddTime],[AddUserId],[FileSize])
	VALUES(@NodeID,@ContentId,@FileRoot,@Category,@AttributeID,@AddTime,@AddUserId,@FileSize)
	SET @ContentUpFileId = @@IDENTITY
END
GO
IF OBJECT_ID('cms_advs_advscontent') IS NOT NULL
BEGIN
    DROP TABLE cms_advs_advscontent
    PRINT '<<< DROPPED TABLE cms_advs_advscontent >>>'
END
GO
IF OBJECT_ID('cms_advs_advscustomers') IS NOT NULL
BEGIN
    DROP TABLE cms_advs_advscustomers
    PRINT '<<< DROPPED TABLE cms_advs_advscustomers >>>'
END
GO
IF OBJECT_ID('cms_advs_advshits') IS NOT NULL
BEGIN
    DROP TABLE cms_advs_advshits
    PRINT '<<< DROPPED TABLE cms_advs_advshits >>>'
END
GO
CREATE TABLE cms_advs_advscontent(
    AdID            int              IDENTITY(1,1),
    CustomersID     int              NULL,
    Name            nvarchar(200)    NULL,
    ShowModel       int              DEFAULT 0 NULL,
    AddTime         datetime         DEFAULT getdate() NOT NULL,
    AddUserId       int              DEFAULT 0 NOT NULL,
    UpdateTime      datetime         DEFAULT getdate() NOT NULL,
    UpdateUserId    int              DEFAULT 0 NOT NULL,
    IsValid         bit              NULL,
    MaturityTime    datetime         DEFAULT getdate() NOT NULL,
    Hits            int              NULL,
    Detial          ntext            NOT NULL,
    PageName        varchar(200)     NULL,
    Redirect        varchar(300)     NULL,
    --[Description]   varchar(300)     NULL,
    CONSTRAINT PK_dbo_cms_advs_advscontent PRIMARY KEY NONCLUSTERED (AdID)
)
GO
IF OBJECT_ID('cms_advs_advscontent') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_advs_advscontent >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_advs_advscontent >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'CustomersID'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'CustomersID'
END
exec sys.sp_addextendedproperty 'MS_Description', '客户ID', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'CustomersID'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Name'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Name'
END
exec sys.sp_addextendedproperty 'MS_Description', 'KeyWord,需要唯一', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Name'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'ShowModel'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'ShowModel'
END
exec sys.sp_addextendedproperty 'MS_Description', '模式:动态和静态(需要生成js文件)', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'ShowModel'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加时间', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'AddUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'UpdateTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'UpdateTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改时间', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'UpdateTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'UpdateUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'UpdateUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '最后修改者id', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'UpdateUserId'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'IsValid'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'IsValid'
END
exec sys.sp_addextendedproperty 'MS_Description', '是否有效,当无效时广告将不显示', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'IsValid'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'MaturityTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'MaturityTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '到期时间', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'MaturityTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Hits'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Hits'
END
exec sys.sp_addextendedproperty 'MS_Description', '点击次数', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Hits'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Detial'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Detial'
END
exec sys.sp_addextendedproperty 'MS_Description', '广告内容', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Detial'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'PageName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'PageName'
END
exec sys.sp_addextendedproperty 'MS_Description', '生成文件名', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'PageName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Redirect'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Redirect'
END
exec sys.sp_addextendedproperty 'MS_Description', '跳转地址', 'schema', 'dbo', 'table', 'cms_advs_advscontent', 'column', 'Redirect'
GO
CREATE TABLE cms_advs_advscustomers(
    CustomersID     int             IDENTITY(1,1),
    CustomerName    varchar(250)    NULL,
    Contact         varchar(200)    NULL,
    Tel             varchar(300)    NULL,
    Fax             varchar(300)    NULL,
    QQ              varchar(25)     NULL,
    Mail            varchar(300)    NULL,
    Address         varchar(500)    NULL,
    CONSTRAINT PK_dbo_cms_advs_advscustomers PRIMARY KEY NONCLUSTERED (CustomersID)
)
GO
IF OBJECT_ID('cms_advs_advscustomers') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_advs_advscustomers >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_advs_advscustomers >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'CustomerName'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'CustomerName'
END
exec sys.sp_addextendedproperty 'MS_Description', '客户名称', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'CustomerName'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Contact'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Contact'
END
exec sys.sp_addextendedproperty 'MS_Description', '联系人', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Contact'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Tel'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Tel'
END
exec sys.sp_addextendedproperty 'MS_Description', '联系电话', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Tel'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Fax'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Fax'
END
exec sys.sp_addextendedproperty 'MS_Description', '传真', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Fax'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'QQ'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'QQ'
END
exec sys.sp_addextendedproperty 'MS_Description', 'QQ', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'QQ'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Mail'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Mail'
END
exec sys.sp_addextendedproperty 'MS_Description', 'Mail', 'schema', 'dbo', 'table', 'cms_advs_advscustomers', 'column', 'Mail'
GO
CREATE TABLE cms_advs_advshits(
    HID          int            IDENTITY(1,1),
    AdID         int            NULL,
    AddTime      datetime       DEFAULT getdate() NOT NULL,
    ip           varchar(20)    NULL,
    AddUserId    int            DEFAULT 0 NOT NULL,
    CONSTRAINT PK_dbo_cms_advs_advshits PRIMARY KEY NONCLUSTERED (HID)
)
GO
IF OBJECT_ID('cms_advs_advshits') IS NOT NULL
    PRINT '<<< CREATED TABLE cms_advs_advshits >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE cms_advs_advshits >>>'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advshits', 'column', 'AddTime'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advshits', 'column', 'AddTime'
END
exec sys.sp_addextendedproperty 'MS_Description', '点击时间', 'schema', 'dbo', 'table', 'cms_advs_advshits', 'column', 'AddTime'
GO
if exists (select * from ::fn_listextendedproperty('MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advshits', 'column', 'AddUserId'))
BEGIN
    exec sys.sp_dropextendedproperty 'MS_Description', 'schema', 'dbo', 'table', 'cms_advs_advshits', 'column', 'AddUserId'
END
exec sys.sp_addextendedproperty 'MS_Description', '添加者id', 'schema', 'dbo', 'table', 'cms_advs_advshits', 'column', 'AddUserId'
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_advshit_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_advshit_Save
GO 
CREATE PROCEDURE cms_advshit_Save
@HID    	int OUTPUT,
@AdID    	int,
@AddTime    	datetime,
@ip    	varchar(20),
@AddUserId    	int
AS
IF (@HID>0) 
BEGIN
	UPDATE cms_advs_advshits
	SET 
		[AdID] = @AdID,
		[AddTime] = @AddTime,
		[ip] = @ip,
		[AddUserId] = @AddUserId
	WHERE [HID]=@HID
END
ELSE
BEGIN
	INSERT INTO cms_advs_advshits([AdID],[AddTime],[ip],[AddUserId])
	VALUES(@AdID,@AddTime,@ip,@AddUserId)
	SET @HID = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_advscustomer_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_advscustomer_Save
GO 
CREATE PROCEDURE cms_advscustomer_Save
@CustomersID    	int OUTPUT,
@CustomerName    	varchar(250),
@Contact    	varchar(200),
@Tel    	varchar(300),
@Fax    	varchar(300),
@QQ    	varchar(25),
@Mail    	varchar(300),
@Address    	varchar(500)
AS
IF (@CustomersID>0) 
BEGIN
	UPDATE cms_advs_advscustomers
	SET 
		[CustomerName] = @CustomerName,
		[Contact] = @Contact,
		[Tel] = @Tel,
		[Fax] = @Fax,
		[QQ] = @QQ,
		[Mail] = @Mail,
		[Address] = @Address
	WHERE [CustomersID]=@CustomersID
END
ELSE
BEGIN
	INSERT INTO cms_advs_advscustomers([CustomerName],[Contact],[Tel],[Fax],[QQ],[Mail],[Address])
	VALUES(@CustomerName,@Contact,@Tel,@Fax,@QQ,@Mail,@Address)
	SET @CustomersID = @@IDENTITY
END
GO
IF EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME='cms_advscontent_Save' AND ROUTINE_TYPE='PROCEDURE')
DROP PROCEDURE cms_advscontent_Save
GO 
CREATE PROCEDURE cms_advscontent_Save
@AdID    	int OUTPUT,
@CustomersID    	int,
@Name    	nvarchar(200),
@ShowModel    	int,
@AddTime    	datetime,
@AddUserId    	int,
@UpdateTime    	datetime,
@UpdateUserId    	int,
@IsValid    	bit,
@MaturityTime    	datetime,
@Hits    	int,
@Detial    	ntext,
@PageName    	varchar(200),
@Redirect    	varchar(300)
--@Description    varchar(300)
AS
IF (@AdID>0) 
BEGIN
	UPDATE cms_advs_advscontent
	SET 
		[CustomersID] = @CustomersID,
		[Name] = @Name,
		[ShowModel] = @ShowModel,
		[AddTime] = @AddTime,
		[AddUserId] = @AddUserId,
		[UpdateTime] = @UpdateTime,
		[UpdateUserId] = @UpdateUserId,
		[IsValid] = @IsValid,
		[MaturityTime] = @MaturityTime,
		[Hits] = @Hits,
		[Detial] = @Detial,
		[PageName] = @PageName,
		[Redirect] = @Redirect
		--[Description]=@Description
	WHERE [AdID]=@AdID
END
ELSE
BEGIN
	INSERT INTO cms_advs_advscontent([CustomersID],[Name],[ShowModel],[AddTime],[AddUserId],[UpdateTime],[UpdateUserId],[IsValid],[MaturityTime],[Hits],[Detial],[PageName],[Redirect])
	VALUES(@CustomersID,@Name,@ShowModel,@AddTime,@AddUserId,@UpdateTime,@UpdateUserId,@IsValid,@MaturityTime,@Hits,@Detial,@PageName,@Redirect)
	SET @AdID = @@IDENTITY
END
GO
SET IDENTITY_INSERT [cms_user_UserBase] ON   
delete from [cms_user_UserBase]
INSERT INTO [cms_user_UserBase]
           (
           [UserBaseId]
           ,[LogName]
           ,[LogPWD]
           ,[Name]
           ,[Sex]
           ,[LastLogTime]
           ,[AddTime]
           ,[PubCount])
     VALUES
           (
           1
           ,'admin'
           ,'e10adc3949ba59abbe56e057f20f883e'/*默认密码 123456*/
           ,'管理员'
           ,'0'
           ,GETDATE()
           ,GETDATE()
           ,0)
GO
SET IDENTITY_INSERT [cms_user_UserBase] OFF